package javagprssrv.Task;

import javagprssrv.JGS_Param;
import java.lang.reflect.Field;
import java.util.Vector;
import java.sql.ResultSet;
import javagprssrv.StructClass.structDYB;
import javagprssrv.StructClass.structTask;
import javagprssrv.Common.CommonClass;
import javagprssrv.DataBase.DBSQLExecute;

public class Old_TaskCreater
{
    private int TaskCounts;
    
    public Old_TaskCreater() {
        this.TaskCounts = 0;
    }
    
    public void CreateTask(final int idxDBConnectionPool, final java.lang.String TaskSQLString, final java.lang.String strDYB) {
        final javagprssrv.DataBase.DBSQLExecute DBExecuter = new javagprssrv.DataBase.DBSQLExecute();
        final java.sql.ResultSet rs = DBExecuter.SQL_Query(idxDBConnectionPool, TaskSQLString);
        final java.util.Vector V = javagprssrv.Common.CommonClass.String2DYBVector(strDYB, ",", "=", "'");
        final int counts = 0;
        boolean canNext = false;
        try {
            canNext = rs.next();
        }
        catch (java.lang.Exception ex) {}
        while (canNext) {
            javagprssrv.StructClass.structTask Task = new javagprssrv.StructClass.structTask();
            Task.Task_Creater = "System.TaskCreater";
            final java.lang.reflect.Field[] f = Task.getClass().getFields();
            for (int idxClassField = 0; idxClassField < f.length; ++idxClassField) {
                boolean isFieldInVector = false;
                boolean isChangLiang = false;
                final java.lang.String ClassFieldName = f[idxClassField].getName();
                java.lang.String VectorValue = "";
                for (int idxVector = 0; idxVector < V.size(); ++idxVector) {
                    if (ClassFieldName.equals(((structDYB)V.elementAt(idxVector)).Name)) {
                        isFieldInVector = true;
                        isChangLiang = (((structDYB)V.elementAt(idxVector)).Type == 0);
                        VectorValue = ((structDYB)V.elementAt(idxVector)).Value;
                        break;
                    }
                }
                if (isFieldInVector) {
                    try {
                        if (isChangLiang) {
                            f[idxClassField].set(Task, VectorValue);
                        }
                        else {
                            f[idxClassField].set(Task, rs.getString(VectorValue));
                        }
                    }
                    catch (java.lang.Exception ee) {
                        ee.printStackTrace();
                    }
                }
            }
            this.AddTask2Tasks(Task);
            Task = null;
            try {
                canNext = rs.next();
            }
            catch (java.lang.Exception ex2) {}
        }
    }
    
    private void AddTask2Tasks(final javagprssrv.StructClass.structTask Task) {
        if (Task.Term_SerialNo.trim().equals("")) {
            return;
        }
        if (Task.Task_Job.trim().equals("")) {
            return;
        }
        final boolean isFind = false;
        synchronized (javagprssrv.JGS_Param.TempTasks) {
            javagprssrv.JGS_Param.TempTasks.add(Task);
        }
    }
}
